#include <fstream>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include "cInputInfo.hh"
using namespace std;


cInputInfo::cInputInfo(char argc, char *argv[]){
	strcpy(outRootFileName,"default");
	deadTime=10; //microseconds
	deadType=0;
	detId=2;
	
	extraAnalysis=0;
	e1_low=30;
	e1_high=31;
	e2_low=30;
	e2_high=31;
	deltaT=10; //microsecs
	TID_nBins=10000;
	TID_max=100*deadTime;
	cardNo=1401;
	
	if ((argc==1||argc>6)&&argc!=9&&argc!=11&&argc!=12){
			cout<<"decay_analysis dirname cardNo dead detId outRootFileName analysisSwitch e1_low e1_high e2_low e2_high DeltaT "<<endl;
			cout<<"\n OR \n";
			cout<<"decay_analysis dirname cardNo dead detId outRootFileName 3 e1_low     e1_high TID_nbins TID_max  "<<endl;
			//      0                  1    2    3      4     5             6      7        8         9    10
			exit(1);
		};
	
	switch(argc){
			case 12:
				e2_low=atoi(argv[9]);
				e2_high=atoi(argv[10]);
				deltaT=atof(argv[11]);
			case 11:
				TID_nBins=atoi(argv[9]);
				TID_max=atof(argv[10]);
			case 9:
				e1_low=atoi(argv[7]);
				e1_high=atoi(argv[8]);
				extraAnalysis=atoi(argv[6]);
			case 6:
				strcpy(outRootFileName,argv[5]);
			case 5:
				detId=atoi(argv[4]);
			case 4:
				deadTime=atoi(argv[3]);
				deadType=deadTime/1000;
				deadTime=deadTime%1000;
			case 3:
				cardNo=atoi(argv[2]);
				strcpy(dirname,argv[1]);
			
	};
	stringstream ss;
	//ss<<dirname<<"/"<<outRootFileName<<"_"<<deadType<<"_"<<deadTime<<".root";
	ss<<dirname<<"/"<<outRootFileName<<".root";
		strcpy(outRootFileName,ss.str().c_str());
		//cout<<"creating "<<ss.str().c_str()<<endl;
		cout<<"reading files from "<<dirname<<endl;
		cout<<"output to "<<outRootFileName<<endl;
		cout<<"using detector on channel "<<detId<<endl<<endl;
		
		ssdir<<"det"<<detId;	
		ssDT<<"dt_"<<deadType*1000+deadTime;
		ssE1<<"e1_"<<e1_low<<"_"<<e1_high;
		ssE2<<"e2_"<<e2_low<<"_"<<e2_high;
}	

ostream& operator<< (ostream& output, const cInputInfo& p){
        return output;
}

istream& operator>> (istream& input, cInputInfo& p){
        
        return input;
}
